package com.maag.Powerwatch;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Timer;
import java.util.TimerTask;

import org.xml.sax.SAXException;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.coders.powergraph.PowerBean;
import com.coders.powergraph.PowerGraph;
import com.maag.Powerwatch.Data.PowerWatch_Common;
import com.maag.Powerwatch.Data.PowerWatch_Home_PowerFooter;
import com.maag.Powerwatch.Data.PowerWatch_Home_PowerRight;
import com.maag.Powerwatch.Data.PowerWatch_Home_RealTimePowerUse;
import com.maag.Powerwatch.Services.PowerWatch_Home_Service_Update;

public class PowerWatch_Home extends Activity
{
	public static final int Request_Code = 0;
	
	EditText textxml;
	ImageView leftScroll,rightScroll;
	ImageView network,setup,kw,price,kwh,minute,hour,day,week,month,year;
	TextView timeText,dateText,realTimePowerUsePower,realTimePowerUseHourlyRate,nextPriceChange,currentElectricityPrice,powerState,demandResponseMode,todayCumulativeCost,todayProjectedCost,todayCumulativeWatt,todayProjectedWatt,previousDayCost,previousDayWatt,pastWeekCost,pastWeekWatt,billingPeriodCumulativeCost,billingPeriodCumulativeWatt,billingPeriodProjectedCost,billingPeriodProjectedWatt;
	ImageView imageTodayCumulativeCostDirection,imageTodayProjectedCostDirection,imagePreviousDayCostDirection,imagePastWeekCostDirection;
	ImageView realTimePowerUseBackground,realTimePowerUseBackground1,rhsRightMove,rhsLeftMove;
//	ImageView imageGraph;
	Handler handler;
	Intent serviceIntent;
	FrameLayout parentForAll;
	Timer timer;
	TimerTask timerTask;
	Context context = this;
	com.coders.powergraph.PowerGraph imageGraph;
	
	int valueFromFirst ,valueFromSecond ;
	
//	GraphView graphChart;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		parentForAll = (FrameLayout)findViewById(R.id.frameParent);
		serviceIntent = new Intent(PowerWatch_Home.this,PowerWatch_Home_Service_Update.class);	
//		imageGraph = (ImageView)findViewById(R.id.imageGraph);    
		
		valueFromFirst =0;
		valueFromSecond = 0;		
		
		network = (ImageView)findViewById(R.id.network);		
		setup = (ImageView)findViewById(R.id.setup);
		kw= (ImageView)findViewById(R.id.kw);
		price= (ImageView)findViewById(R.id.sss);
		kwh = (ImageView)findViewById(R.id.kwh);
		//		avg= (TextView)findViewById(R.id.avg);
		minute = (ImageView)findViewById(R.id.minute);
		hour= (ImageView)findViewById(R.id.hour);
		day = (ImageView)findViewById(R.id.day);
		week= (ImageView)findViewById(R.id.week);
		month= (ImageView)findViewById(R.id.month);
		year= (ImageView)findViewById(R.id.year);
		
		imageGraph = (PowerGraph)findViewById(R.id.graph);
		imageGraph.setVerticalGridLineCount(25 );
		
		realTimePowerUsePower = (TextView)findViewById(R.id.realTimePowerUsePower);
		realTimePowerUseHourlyRate = (TextView)findViewById(R.id.realTimePowerUseHourlyRate);
		timeText = (TextView)findViewById(R.id.timeText);
		dateText = (TextView)findViewById(R.id.dateText);
		nextPriceChange= (TextView)findViewById(R.id.nextPriceChange);
		currentElectricityPrice = (TextView)findViewById(R.id.currentElectricityPrice);
		powerState= (TextView)findViewById(R.id.powerState);
		demandResponseMode = (TextView)findViewById(R.id.demandResponseText);
		todayCumulativeCost = (TextView)findViewById(R.id.todayCumulativeCost);
		todayCumulativeWatt= (TextView)findViewById(R.id.todayCumulativeWatt);
		todayProjectedCost= (TextView)findViewById(R.id.todayProjectedCost);
		todayProjectedWatt= (TextView)findViewById(R.id.todayProjectedWatt);
		previousDayCost= (TextView)findViewById(R.id.previousDaycost);
		previousDayWatt= (TextView)findViewById(R.id.previousDayWatt);
		pastWeekCost= (TextView)findViewById(R.id.pastWeekCost);
		pastWeekWatt= (TextView)findViewById(R.id.pastWeekWatt);
		billingPeriodCumulativeCost= (TextView)findViewById(R.id.billingPeriodCumulativeCost);
		billingPeriodCumulativeWatt= (TextView)findViewById(R.id.billingPeriodCumulativeWatt);
		billingPeriodProjectedCost= (TextView)findViewById(R.id.billingPeriodProjectedCost);
		billingPeriodProjectedWatt= (TextView)findViewById(R.id.billingPeriodProjectedWatt);
		
		
		imagePastWeekCostDirection = (ImageView)findViewById(R.id.pastWeekCostDirection);
		imagePreviousDayCostDirection = (ImageView)findViewById(R.id.previousDayCostDirection);
		imageTodayCumulativeCostDirection = (ImageView)findViewById(R.id.todayCumulativeCostDirection);
		imageTodayProjectedCostDirection = (ImageView)findViewById(R.id.todayProjectedCostDirection);
		realTimePowerUseBackground = (ImageView)findViewById(R.id.backImageForCurrent);
		realTimePowerUseBackground1 = (ImageView)findViewById(R.id.backImageForCurrent1);
		
		
		rhsLeftMove = (ImageView)findViewById(R.id.rhsLeftMove);
		rhsRightMove = (ImageView)findViewById(R.id.rhsRightMove);
		
		rhsLeftMove.setOnClickListener(clickListener);
		rhsRightMove.setOnClickListener(clickListener);
		network.setOnClickListener(clickListener);
		setup.setOnClickListener(clickListener);		
		kw.setOnClickListener(clickListener);
		price.setOnClickListener(clickListener);
//		avg.setOnClickListener(clickListener);
		kwh.setOnClickListener(clickListener);
		minute.setOnClickListener(clickListener);
		hour.setOnClickListener(clickListener);
		day.setOnClickListener(clickListener);
		week.setOnClickListener(clickListener);
		month.setOnClickListener(clickListener);
		year.setOnClickListener(clickListener);	
		
//		handler = new Handler();
//		UpdateMembers();
		
		
		
//		timer = new Timer();
//				
//		timerTask = new TimerTask() {
//			
//			@Override
//			public void run() {
//				runOnUiThread(action);
//			}
//		};
//		timer.scheduleAtFixedRate(timerTask, 1000, 5000);
		
		
		SharedPreferences.Editor edit = getSharedPreferences("password", 0).edit();
		edit.putString("userPassword", "powerwatch");
		edit.commit();
	}
	
private BroadcastReceiver UiUpdateReceiver = new BroadcastReceiver() {
	
	@Override
	public void onReceive(Context context, Intent intent) {
		try {
			UpdateUi(intent);
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
};
		
private void UpdateUi(Intent intent) throws SAXException
{
//	try {
//		String xmlStringForPowerFooter = intent.getStringExtra("xmlPowerFooter");
//		xmlStringForPowerFooter.trim();
//		
//		String xmlStringForPowerRight = intent.getStringExtra("xmlPowerRight");
//		xmlStringForPowerRight.trim();
//		
//		String xmlStringForChart = intent.getStringExtra("xmlForChart");
//		xmlStringForChart.trim();
//		
//		if(!xmlStringForPowerFooter.equals(""))
//		{
//		
//		Log.w("Xml PowerFooter", xmlStringForPowerFooter);
//
//		}
//		
//		if(!xmlStringForPowerRight.equals(""))
//		{
//			InputSource source = new InputSource(new StringReader(xmlStringForPowerRight));
//			source.setEncoding("iso-8859-1");
//			xr_for_PowerRight.parse(source);
//			Log.w("Xml PowerRight", xmlStringForPowerRight);
//		}
//		
//		if(!xmlStringForChart.equals(""))
//		{
//			InputSource source = new InputSource(new StringReader(xmlStringForChart));
//			source.setEncoding("iso-8859-1");
//			xr_for_Chart.parse(source);
//			Log.w("Xml Chart", xmlStringForChart);
//		}
//	
//	} catch (Exception e) {
//		// TODO Auto-generated catch block
//		e.printStackTrace();
//	}
	
	
//	handler.postDelayed(new Runnable() {
//		
//		@Override
//		public void run() {
////			timeText.setText(PowerWatch_DataHandler.getUpdatedMembers().time);
//			
//		}
//	}, 2000);
//	textxml.setText(intent.getStringExtra("xml"));
	try{
	timeText.setText(PowerWatch_Home_PowerFooter.time);
	dateText.setText(PowerWatch_Home_PowerFooter.date);
//	realTimePowerUse.setText(intent.getStringExtra("realTimePowerUse"));
	nextPriceChange.setText(PowerWatch_Home_PowerFooter.nextPriceChange);
	currentElectricityPrice.setText(PowerWatch_Home_PowerFooter.currentElectricityPrice);
	powerState.setText(PowerWatch_Home_PowerFooter.powerState);
	demandResponseMode.setText(PowerWatch_Home_PowerFooter.demandResponseMode);
	todayCumulativeCost.setText(PowerWatch_Home_PowerRight.todayCumulativeCost);
	todayCumulativeWatt.setText(PowerWatch_Home_PowerRight.todayCumulativePower);
	todayProjectedCost.setText(PowerWatch_Home_PowerRight.todayProjectedCost);
	todayProjectedWatt.setText(PowerWatch_Home_PowerRight.todayProjectedPower);
	previousDayCost.setText(PowerWatch_Home_PowerRight.previousDayCost);
	previousDayWatt.setText(PowerWatch_Home_PowerRight.previousDayPower);
	pastWeekCost.setText(PowerWatch_Home_PowerRight.pastWeekCost);
	pastWeekWatt.setText(PowerWatch_Home_PowerRight.pastWeekPower);
	billingPeriodCumulativeCost.setText(PowerWatch_Home_PowerRight.billingPeriodCumulativeCost);
	billingPeriodCumulativeWatt.setText(PowerWatch_Home_PowerRight.billingPeriodCumulativePower);
	billingPeriodProjectedCost.setText(PowerWatch_Home_PowerRight.billingPeriodProjectedCost);
	billingPeriodProjectedWatt.setText(PowerWatch_Home_PowerRight.billingPeriodProjectedPower);
	
	
	realTimePowerUseHourlyRate.setText(PowerWatch_Home_RealTimePowerUse.hourlyRate);
	realTimePowerUsePower.setText(PowerWatch_Home_RealTimePowerUse.power);
	
	if(PowerWatch_Home_RealTimePowerUse.color.trim().equals("green"))
	{
		realTimePowerUseBackground.setImageResource(R.drawable.green_475x80);
		realTimePowerUseBackground1.setImageResource(R.drawable.green_475x80);
	}
	else if(PowerWatch_Home_RealTimePowerUse.color.trim().equals("red"))
	{
		realTimePowerUseBackground.setImageResource(R.drawable.red_475x80);
		realTimePowerUseBackground1.setImageResource(R.drawable.red_475x80);
	}
	else if(PowerWatch_Home_RealTimePowerUse.color.trim().equals("yellow"))
	{
		realTimePowerUseBackground.setImageResource(R.drawable.yellow_475x80);
		realTimePowerUseBackground1.setImageResource(R.drawable.yellow_475x80);
	}
	
	
	
	
	
	if(PowerWatch_Home_PowerRight.todayCumulativeCostDirection.equals("increase"))
	{
		imageTodayCumulativeCostDirection.setImageResource(R.drawable.arrow_up);
	}
	else if(PowerWatch_Home_PowerRight.todayCumulativeCostDirection.equals("decrease"))
	{
		imageTodayCumulativeCostDirection.setImageResource(R.drawable.arrow_down);
	}
	
	if(PowerWatch_Home_PowerRight.todayProjectedCostDirection.equals("increase"))
	{
		imageTodayProjectedCostDirection.setImageResource(R.drawable.arrow_up);
	}
	else if(PowerWatch_Home_PowerRight.todayProjectedCostDirection.equals("decrease"))
	{
		imageTodayProjectedCostDirection.setImageResource(R.drawable.arrow_down);
	}
	
	if(PowerWatch_Home_PowerRight.pastWeekCostDirection.equals("increase"))
	{
		imagePastWeekCostDirection.setImageResource(R.drawable.arrow_up);
	}
	else if(PowerWatch_Home_PowerRight.pastWeekCostDirection.equals("decrease"))
	{
		imagePastWeekCostDirection.setImageResource(R.drawable.arrow_down);
	}
	
	if(PowerWatch_Home_PowerRight.previousDayCostDirection.equals("increase"))
	{
		imagePreviousDayCostDirection.setImageResource(R.drawable.arrow_up);
	}
	else if(PowerWatch_Home_PowerRight.previousDayCostDirection.equals("decrease"))
	{
		imagePreviousDayCostDirection.setImageResource(R.drawable.arrow_down);
	}
	
	// TODO Auto-generated method stub
//			imageGraph.setImageDrawable(LoadImageFromURL(PowerWatch_UpdateMembers_For_Chart.URL));
	
	Log.e("Xml FIle processing", intent.getStringExtra("xmlRight"));
	
	}
	catch (Exception e) {
		
	}
	
	
}

		private Drawable LoadImageFromURL(String url)
		{
			// progress_Dialog.show(MyContext, null, null);
			try
			{
				InputStream is = (InputStream) new URL(url).getContent();
				Drawable d = Drawable.createFromStream(is, "src");
				return d;
			}catch (Exception e) {
				System.out.println(e);
				return null;
			}
	}
		@Override
		protected void onPause() {
			unregisterReceiver(UiUpdateReceiver);
			stopService(serviceIntent);
			super.onPause();
		}

		@Override
		protected void onResume() {
			startService(serviceIntent);
			registerReceiver(UiUpdateReceiver, new IntentFilter(PowerWatch_Home_Service_Update.BROADCAST_ACTION));

			 valueFromFirst = kw.getId();
			 valueFromSecond = hour.getId();
			
//			imageGraph.setBackgroundResource(R.drawable.hourkw);
			realTimePowerUseBackground.setBackgroundResource(R.drawable.yellow_475x80);
			realTimePowerUseBackground1.setBackgroundResource(R.drawable.yellow_475x80);
			
			if(!HaveNetworkConnection())
			{
				Toast.makeText(getApplicationContext(),"Please Check Your Internet Connection" ,Toast.LENGTH_LONG).show();
			}
			
			PowerWatch_Common.myList = new LinkedList<PowerBean>();
			PowerWatch_Common.myList = getPowerBeans(context);
			imageGraph.invalidate();
			super.onResume();			
		}
		
		private boolean HaveNetworkConnection()
		 {
		     boolean HaveConnectedWifi = false;
		     boolean HaveConnectedMobile = false;

		     ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		     NetworkInfo[] netInfo = cm.getAllNetworkInfo();
		     for (NetworkInfo ni : netInfo)
		     {
		         if (ni.getTypeName().equalsIgnoreCase("WIFI"))
		             if (ni.isConnected())
		                 HaveConnectedWifi = true;
		         if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
		             if (ni.isConnected())
		                 HaveConnectedMobile = true;
		     }
		     return HaveConnectedWifi || HaveConnectedMobile;
		 }
		@Override
		protected void onDestroy() {
			super.onDestroy();
		}





	public OnClickListener clickListener = new  OnClickListener() {
		
		@Override
		public void onClick(View v) {
			if(v.getId()==setup.getId())
			{
				Intent intent = new Intent(PowerWatch_Home.this,PowerWatch_Setup.class);
				startActivity(intent);
				
			}
			else if(v.getId()==network.getId())
			{

				Intent intent = new Intent(PowerWatch_Home.this,PowerWatch_NetworkDevices.class);
				startActivity(intent);
			}
			else if(v.getId()==kw.getId())
			{
				kw.setImageResource(R.drawable.kw_2);
				price.setImageResource(R.drawable.sss_1);
				kwh.setImageResource(R.drawable.kwh_1);
				valueFromFirst=v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==price.getId())
			{
				kw.setImageResource(R.drawable.kw_1);
				price.setImageResource(R.drawable.sss_2);
				kwh.setImageResource(R.drawable.kwh_1);
				
				valueFromFirst=v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==kwh.getId())
			{
				
				kw.setImageResource(R.drawable.kw_1);
				price.setImageResource(R.drawable.sss_1);
				kwh.setImageResource(R.drawable.kwh_2);
				
				valueFromFirst=v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==minute.getId())
			{
				
				minute.setImageResource(R.drawable.min_2);
				hour.setImageResource(R.drawable.hrs_1);
				day.setImageResource(R.drawable.day_1);
				week.setImageResource(R.drawable.week_1);
				month.setImageResource(R.drawable.mth_1);
				year.setImageResource(R.drawable.year_1);
				
				valueFromSecond =v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);

			}
			else if(v.getId()==hour.getId())
			{
				minute.setImageResource(R.drawable.min_1);
				hour.setImageResource(R.drawable.hrs_2);
				day.setImageResource(R.drawable.day_1);
				week.setImageResource(R.drawable.week_1);
				month.setImageResource(R.drawable.mth_1);
				year.setImageResource(R.drawable.year_1);
				
				valueFromSecond =v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==day.getId())
			{
				minute.setImageResource(R.drawable.min_1);
				hour.setImageResource(R.drawable.hrs_1);
				day.setImageResource(R.drawable.day_2);
				week.setImageResource(R.drawable.week_1);
				month.setImageResource(R.drawable.mth_1);
				year.setImageResource(R.drawable.year_1);
				
				valueFromSecond =v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==week.getId())
			{
				minute.setImageResource(R.drawable.min_1);
				hour.setImageResource(R.drawable.hrs_1);
				day.setImageResource(R.drawable.day_1);
				week.setImageResource(R.drawable.week_2);
				month.setImageResource(R.drawable.mth_1);
				year.setImageResource(R.drawable.year_1);
				
				valueFromSecond =v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==month.getId())
			{
				minute.setImageResource(R.drawable.min_1);
				hour.setImageResource(R.drawable.hrs_1);
				day.setImageResource(R.drawable.day_1);
				week.setImageResource(R.drawable.week_1);
				month.setImageResource(R.drawable.mth_2);
				year.setImageResource(R.drawable.year_1);
				
				valueFromSecond =v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==year.getId())
			{
				minute.setImageResource(R.drawable.min_1);
				hour.setImageResource(R.drawable.hrs_1);
				day.setImageResource(R.drawable.day_1);
				week.setImageResource(R.drawable.week_1);
				month.setImageResource(R.drawable.mth_1);
				year.setImageResource(R.drawable.year_2);
				

				valueFromSecond =v.getId();
				UpdateGraphImage(valueFromFirst, valueFromSecond);
			}
			else if(v.getId()==rhsLeftMove.getId())
			{
				Toast.makeText(getApplicationContext(),"Values will be updated in next version", Toast.LENGTH_SHORT).show();
			}
			else if(v.getId()==rhsRightMove.getId())
			{
				Toast.makeText(getApplicationContext(),"Values will be updated in next version", Toast.LENGTH_SHORT).show();
			}
		
		}
	};

	
	
	public void UpdateGraphImage(int firstElement,int secondElement)
	{
		Log.d("Update Graph Image", "Condition comes to update graph image");
		if(firstElement==kw.getId() && secondElement == minute.getId())
		{
//			imageGraph.setBackgroundResource(R.drawable.minkw);
			Log.d("Inside", "Inside first one");
		}
		else if(firstElement == kw.getId() && secondElement == hour.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.hourkw);
			Log.d("Inside", "Inside Second one");
		}
		else if(firstElement == kw.getId() && secondElement == day.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.daykw);
		}
		else if(firstElement == kw.getId() && secondElement == week.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.weekkw);
		}
		else if(firstElement == kw.getId() && secondElement == month.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.monthkw);
		}
		else if(firstElement == kw.getId() && secondElement == year.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.yearkw);
		}
		else if(firstElement == kwh.getId() && secondElement == minute.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.minkwh);
		}
		else if(firstElement == kwh.getId() && secondElement == hour.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.hourkwh);
		}
		else if(firstElement == kwh.getId() && secondElement == day.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.daykwh);
		}
		else if(firstElement == kwh.getId() && secondElement == week.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.weekkwh);
		}
		else if(firstElement == kwh.getId() && secondElement == month.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.monthkwh);
		}
		else if(firstElement == kwh.getId()  && secondElement == year.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.yearkwh);
		}
		else if(firstElement == price.getId() && secondElement == minute.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.mincost);
		}
		else if(firstElement == price.getId() && secondElement == hour.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.hourcost);
		}
		else if(firstElement == price.getId() && secondElement == day.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.daycost);
		}
		else if(firstElement == price.getId() && secondElement == week.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.weekcost);
		}
		else if(firstElement == price.getId() && secondElement == month.getId())
		{	
//			imageGraph.setBackgroundResource(R.drawable.monthcost);
		}
		else if(firstElement == price.getId()  && secondElement == year.getId())
		{		
//			imageGraph.setBackgroundResource(R.drawable.yearcost);
		}
		
	}
	
	
	
	
	
	//-------------------------Get Bean Values to Update Graph---------//
	public static List< PowerBean > getPowerBeans( Context context )
    {
        List< PowerBean > list = new LinkedList< PowerBean >();

        try
        {
        	Log.e("File Reading", "File Reading Processed");
            InputStream in = context.getAssets().open( "weekcost.txt" );
            BufferedReader br = new BufferedReader( new InputStreamReader( in ) );
            String strLine;
            StringTokenizer tokenizer;
            while ( ( strLine = br.readLine() ) != null )
            {
                tokenizer = new StringTokenizer( strLine, "," );

                PowerBean bean = new PowerBean();
                if ( tokenizer.hasMoreElements() )
                    bean.setX( new Float( tokenizer.nextElement().toString() ) );
                if ( tokenizer.hasMoreElements() )
                    bean.setY( new Float( tokenizer.nextElement().toString() ) );
                if ( tokenizer.hasMoreElements() )
                {
                    String color = tokenizer.nextElement().toString();
                    if ( "red".equalsIgnoreCase( color ) )
                    {
                        bean.setColorCode( Color.RED );
                    }
                    else if ( "green".equalsIgnoreCase( color ) )
                    {
                        bean.setColorCode( Color.GREEN );
                    }
                    else
                    {
                        bean.setColorCode( Color.YELLOW );
                    }
                }
                list.add( bean );
            }
            in.close();
        }
        catch ( Exception e )
        {
            Log.e( "DataProvider", e.getMessage(), e );
        }

        return list;

    }



}
